//
//  YSRegisterViewController.m
//  YSZC
//
//  Created by 张斌 on 16/4/12.
//  Copyright © 2016年 YueShiKeJi. All rights reserved.
//

#import "YSRegisterViewController.h"









#import "YSDoViewManager.h"
#import "LoadVcManager.h"






#import "YSTextfield.h"

@interface YSRegisterViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIView *userview;
@property (weak, nonatomic) IBOutlet UIView *passview;

@property (weak, nonatomic) IBOutlet UIView *phoneview;
@property (weak, nonatomic) IBOutlet UIView *checkview;
@property (weak, nonatomic) IBOutlet UIButton *getcode_btn;
@property (weak, nonatomic) IBOutlet UIButton *rxm_btn;
@property (weak, nonatomic) IBOutlet UIButton *rtz_btn;
@property (weak, nonatomic) IBOutlet UIButton *register_btn;
@property (weak, nonatomic) IBOutlet UIButton *protcol_btn;
@property (weak, nonatomic) IBOutlet UITextField *user_tx;
@property (weak, nonatomic) IBOutlet UITextField *pass_tx;
@property (weak, nonatomic) IBOutlet UITextField *phonr_tx;
@property (weak, nonatomic) IBOutlet UITextField *checkcode_tx;
@end

@implementation YSRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.checkcode_tx.delegate = self;
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
}

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
    [[YSDoViewManager sharedmanager] settoyuanWithview:@[self.userview,self.passview,self.phoneview,self.checkview,self.getcode_btn,self.rxm_btn,self.rtz_btn,self.register_btn]];
}
- (IBAction)protcol_btnclick:(UIButton *)sender {
    self.protcol_btn.selected = !self.protcol_btn.selected;
}
- (IBAction)return_btnclick:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

// 跟随键盘
-(void)changeViewFrame:(NSNotification *)noti{
    //1.获取 结束时候的Frame即可
    //    NSLog(@"%@",noti);
    //2.获取结束的Frame
    CGRect endRect =  [noti.userInfo[@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];
    //拿 结束的Frame中的y值 跟界面的高度做减法 得到 最终 控制器的View 的y值
    CGFloat endY = endRect.origin.y-self.view.frame.size.height+120;
    
    //设置给控制器的View的Frame即可
    CGRect oldFrame=self.view.frame;
    if (endY>0) {
        endY = 0;
    }
    oldFrame.origin.y=endY;
    
    
    self.view.frame=oldFrame;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    if ([textField isKindOfClass:[YSTextfield class]]) {
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeViewFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
        
    }else{
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
    }
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}

// 注册项目方
- (IBAction)rxmbtnclick
:(UIButton *)sender {
    [self.navigationController pushViewController:[LoadVcManager sbVCWithsbname:@"YSRegisterxmViewController"] animated:YES];
}

// 注册投资人
- (IBAction)rtzbtnclick:(UIButton *)sender {
//    
    [self.navigationController pushViewController:[LoadVcManager sbVCWithsbname:@"YSRegistertzgrViewController"] animated:YES];
    
    
}




@end
